<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
    content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script>
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '录入日财务数据',
										iconCls : 'icon-add',
										handler : function() {
											var new_win = window
													.open(
															"<c:url value='/jsp/openIndexSun.jsp?url=/financing/preSaveFinancing.do'/>",
															"sun",
															"width=1200px,height=600px,status=no,scrollbars=yes");
											new_win.focus();
											$('#' + listDisplayEId).datagrid(
													'reload');
										}
									},
									{
										id : listDisplayEId + '_btn_edit',
										text : '修改日财务数据',
										iconCls : 'icon-edit',
										handler : function() {
											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												var new_win = window
														.open(
																"<c:url value='/jsp/openIndexSun.jsp?url=/financing/preUpdateFinancing.do'/>"
																		+ "?date="
																		+ row[0]['date'],
																"sun",
																"width=1200px,height=600px,status=no,scrollbars=yes");
												new_win.focus();
												$('#' + listDisplayEId)
														.datagrid('reload');
											}
											$('#' + listDisplayEId).datagrid(
													'clearSelections');
										}
									},
									{
										id : listDisplayEId + '_btn_search',
										text : '查看日财务数据',
										iconCls : 'icon-search',
										handler : function() {
											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												var new_win = window
														.open(
																"<c:url value='/jsp/openIndexSun.jsp?url=/financing/preLookFinancing.do'/>"
																		+ "?date="
																		+ row[0]['date'],
																"sun",
																"width=1200px,height=600px,status=no,scrollbars=yes");
												new_win.focus();
												$('#' + listDisplayEId)
														.datagrid('reload');
											}
											$('#' + listDisplayEId).datagrid(
													'clearSelections');
										}
									},
									{
                                        id : listDisplayEId + '_btn_del',
                                        text : '删除',
                                        iconCls : 'icon-cancel',
                                        handler : function() {
                                            
                                            var row = $('#'+listDisplayEId).datagrid('getSelections');      
                                            if(row.length == 0){
                                                $.messager.alert('提示','请选择一条记录操作！','info');
                                                return;
                                            }else{
                                                var str = "materId=" + row[0]['materId']+"&materLevel=" + row[0]['materLevel']+"&supId=" + row[0]['supId']; 
                                                $.messager.confirm('提示', '是否删除该条记录？', function(r){
                                                    if (r){         
                                                        $.ajax({type:'post',url:"<c:url value='/mater/deleteMater.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
                                                        success:function(data){
                                                            if(data.success){
                                                                $.messager.alert("提示", "删除成功！", 'info');
                                                                $('#'+listDisplayEId).datagrid('reload');
                                                            }else{
                                                                $.messager.alert("提示", data.msg, 'warning');
                                                            }
                                                        },
                                                        error:function(){
                                                            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                                        }
                                                    });
                                                }
                                                $('#'+listDisplayEId).datagrid('reload');
                                                $('#'+listDisplayEId).datagrid('clearSelections');
                                                });
                                            }
                                        }
                                    }],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							}

						});
	};
	$(document).ready(function() {
		initList('listDisplay');
	});

	function searchInfo() {
		if ($('#dateStart').combobox('getValue') == '') {
			alert("起始日不能为空");
		} else if ($('#dateEnd').datebox('getValue') == '') {
			alert("截止日不能为空");
		} else {
			$('#listDisplay').datagrid('load', {
				initFlag : 1,
				dateEnd : $('#dateEnd').datebox('getValue'),
				dateStart : $('#dateStart').datebox('getValue')
			});
		}

	}
	function tea() {
		$('#listDisplay').datagrid('load');
	}

	// 种类格式
	var turnoverTypeClass;
	$.ajax({
		async : false,
		url : "<c:url value='/turnover/turnoverTypePullDown.do?space=0'/>",
		type : "post",
		data : {
			turnoverType : 1
		},
		success : function(data) {
			turnoverTypeClass = data;
			if (typeof (turnoverTypeClass) == 'string') {
				turnoverTypeClass = JSON.parse(turnoverTypeClass);
			}
		}
	});
</script>
</head>
<body>
	<table width="98%">
		<tr>
			<td>
				<div
					style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
					class="easyui-panel" title="查询" iconCls="icon-search"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">
					<form id="searchForm" name="searchForm" method="post">
						<div>
							<table cellpadding="5">
								<tr>
									<td>起始日期</td>
									<td><input class="easyui-datebox" editable="false"
										id="dateStart" name="dateStart" required="true"></input></td>
							    </tr>
							    <tr>
									<td>截止日期</td>
									<td><input class="easyui-datebox" editable="false"
										id="dateEnd" name="dateEnd" required="true"></input></td>
								</tr>
								<tr><td><input type="button" onclick="searchInfo()" value="查询"></td></tr>
							</table>
						</div>
					</form>
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<table id="listDisplay" title="日财务操作列表" iconCls="icon-list"
					singleSelect="true" idField="date"
					url="<c:url value="/financing/listFinancingListForCust.do"/>"
					loadMsg="请稍候......" pagination="true" pageSize="20"
					pageList="[10,20,30,40,50]" rownumbers="true" sortOrder="asc">
					<thead>
						<tr>
							<th field="id" width="25" align="center" checkbox="true"></th>
							<th field="date" width="80" sortable="true">日期</th>
							<th field="custId" width="60" sortable="true">客户ID</th>
							<th field="custName" width="80" sortable="true">客户名</th>
							<th field="turnoverId" width="80" sortable="true" hidden='true'>ID
							</th>
							<th field="turnoverTypeDetialValue" width="150" sortable="true">营业额类型
							</th>
							<th field="turnoverValueTotal" width="100" sortable="true">日营业额
							</th>
							<th field="turnoverState" width="80" sortable="true"
								formatter="formaterTurnoverState">状态</th>
							<th field="costId" width="80" sortable="true" hidden='true'>ID
							</th>
							<th field="costTypeDetialValue" width="150" sortable="true">费用类型
							</th>
							<th field="costValueTotal" width="100" sortable="true">日费用
							</th>
							<th field="costState" width="80" sortable="true"
								formatter="formaterTurnoverState">状态</th>
						</tr>
					</thead>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>